﻿using System.Windows;
using System.Windows.Controls;

namespace Tequila.AugmentedReality.Views
{
    public class CompassPoiView :Control
    {
        private const string IN_FOV_VISUAL_STATE = "InFov";
        private const string NOT_IN_FOV_VISUAL_STATE = "NotInFov";

        public CompassPoiView()
        {
            base.DefaultStyleKey = typeof (CompassPoiView);
            
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            VisualStateManager.GoToState(this, NOT_IN_FOV_VISUAL_STATE, false);
        }

        public static readonly DependencyProperty IsInFovProperty =
            DependencyProperty.Register("IsInFov", typeof (bool), typeof (CompassPoiView), new PropertyMetadata(default(bool), PropertyChangedCallback));

        private static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var compassPoiView = (CompassPoiView) dependencyObject;

            if ((bool)dependencyPropertyChangedEventArgs.NewValue)
                VisualStateManager.GoToState(compassPoiView, IN_FOV_VISUAL_STATE, false);
            else
                VisualStateManager.GoToState(compassPoiView, NOT_IN_FOV_VISUAL_STATE, false);
        }

        public bool IsInFov
        {
            get { return (bool) GetValue(IsInFovProperty); }
            set { SetValue(IsInFovProperty, value); }
        }
    }
}
